package com.example.nacosdemo;

import cn.highsuccess.connPool.api.tssc.UnionTsscResult;
import fpsp.hsm.client.UnionTssc;

public class Test {
    public static void main(String[] args) throws Exception{
//初始化
        String configPath = "server.properties";
        UnionTssc tssc = UnionTssc.getInstance(configPath);
//产生PIK
        UnionTsscResult result = tssc.hsm_generate_pik("test");
        String[] key1 = new String[2];
        key1 = result.getStrArry();
        System.out.println("generate_pik,keyValue="+key1[0]);
        System.out.println("generate_pik,checkValue="+key1[1]);
//产生MAK
        result = tssc.hsm_generate_mak("test");
        String[] key2 = new String[2];
        key2 = result.getStrArry();
        System.out.println("generate_mak,keyValue="+key2[0]);
        System.out.println("generate_mak,checkValue="+key2[1]);
//存储mak
        result = tssc.hsm_store_mak("test",key2[0],key2[1]);
        System.out.println("store_mak="+result.getbool());
//存储pik
        result = tssc.hsm_store_pik("test",key1[0],key1[1]);
        System.out.println("store_pik="+result.getbool());
//计算mac
        UnionTsscResult Text1 = tssc.hsm_generate_mac("test","1234567890123456".getBytes());
        if(Text1. getErrCode() != 0){
            System.out.println("hsm_genarate_mac  is Err!!!");
            System.out.println("Errcode="+Text1.getErrCode());
            System.out.println("ErrMsg="+Text1.getErrMsg());
        }
        else
            System.out.println("MAC="+Text1.getStr());
//加密数字pin
        UnionTsscResult Text2 = tssc.hsm_encrypt_pin("test","071234567","1234567890123456");
        if(Text2. getErrCode() != 0){
            System.out.println("hsm_encrypt_pin  is Err!!!");
            System.out.println("Errcode="+Text2.getErrCode());
            System.out.println("ErrMsg="+Text2.getErrMsg());
        }
        else
            System.out.println("PIN="+Text2.getStr());

        System.exit(0);
    }
}
